#include <iostream>
#include <map>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;

bool is_alpha(const string &word){
    auto it1=word.begin();
    auto it2=word.end();
    while(it1!=it2){
        if(!isalpha(*it1)){
            return false;
        }
        it1++;
    }
    return true;
}

class Dictionary{
public:
    void read(const string &filename){
        ifstream ifs(filename);
        if(!ifs){
            cerr << "file is not found" << endl;
            return;
        }
        string line;
        while(getline(ifs,line)){
            istringstream iss(line);
            string word;
            while(iss >> word){
                if(is_alpha(word)){
                    ++_dict[word];
                }
            }
        }
    }

    void store(const string &filename){
        ofstream ofs(filename);
        auto it1=_dict.begin();
        auto it2=_dict.end();
        while(it1!=it2){
            ofs<<it1->first<<" "<<it1->second<<endl;
            ++it1;
        }
        ofs.close();
    }

private:
    map<string,int> _dict;
};

void test(){
    Dictionary dict;
    dict.read("The_Holy_Bible.txt");
    dict.store("bible.txt");
}

int main()
{
    test();
    return 0;
}

